import pygame, sys
from pygame.locals import *

# set up pygame
pygame.init()

S_WIDTH = 650
S_HEIGHT = 480

# set up the window
windowSurface = pygame.display.set_mode((S_WIDTH, S_HEIGHT), 0, 32)
pygame.display.set_caption('ch2_6')

BLACK = (0, 0, 0)

MAP_W = 50
MAP_H = 50

mapRect = pygame.Rect(0, 0, MAP_W, MAP_H)

map0 = pygame.image.load('map0.bmp')
map1 = pygame.image.load('map1.bmp')
map2 = pygame.image.load('map2.bmp')
maps = [map0, map1, map2]

map_array = [ [2,2,2,2,0,1,0,1], 
              [0,2,2,0,0,0,1,1],
              [0,0,0,0,0,0,0,1],
              [2,0,0,0,0,0,2,2],
              [2,0,0,0,0,2,2,2],
              [2,0,0,0,2,2,0,0],
              [0,0,2,2,2,0,0,1],
              [0,0,2,0,0,0,1,1] ]

windowSurface.fill(BLACK)

for ridx, r in enumerate(map_array):
    for cidx, c in enumerate(r):
        rect = mapRect.move(cidx * MAP_W, ridx * MAP_H)
        windowSurface.blit(maps[c], rect)

pygame.display.update()

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
